/**
 * $Id: EmployeeEditor.java 7 2011-03-09 07:13:54Z r.middel@gmail.com $
 *
 * Copyright (C) 2010 mrBussy.eu
 * 
 * WickedHRM is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * WickedHRM is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package eu.mrbussy.applications.wickedhrm.gui.editors;

import java.text.ParseException;
import java.util.Calendar;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;

import eu.mrbussy.applications.wickedhrm.data.Employee;

public class EmployeeEditor extends SaveablePart {

	/**
	 * ID of this class
	 */
	public static final String ID = "eu.mrbussy.applications.wickedhrm.gui.editors.EmployeeEditor";
	/**
	 * Instance of the employee currently being edited in this screen
	 */
	private Employee employee;

	public EmployeeEditor() {
		// TODO Auto-generated constructor stub
	}

	public EmployeeEditorInput getInput() {
		return (EmployeeEditorInput) super.getEditorInput();
	}

	/**
	 * @author R. Middel
	 * @since 1.0
	 * @see org.eclipse.ui.ISaveablePart#doSave(IProgressMonitor monitor)
	 */
	@Override
	public void doSave(IProgressMonitor monitor) {
		// TODO Auto-generated method stub

	}

	/**
	 * @author R. Middel
	 * @since 1.0
	 * @see org.eclipse.ui.ISaveablePart#doSaveAs()
	 */
	@Override
	public void doSaveAs() {
		// Function obsolete for this editor
	}

	@Override
	public void init(IEditorSite site, IEditorInput input)
			throws PartInitException {
		setSite(site);
		setInput(input);

		this.employee = this.getInput().getEmployee();
		setPartName("Person " + this.employee.getLastname());

	}

	@Override
	public void createPartControl(Composite parent) {
		Label label = null;
		Employee emp = this.getInput().getEmployee();

		GridLayout layout = new GridLayout(2, false);
		parent.setLayout(layout);

		label = new Label(parent, SWT.NONE);
		label.setText("Employee number:");
		label = new Label(parent, SWT.NONE);
		label.setText(String.valueOf(emp.getEmployeeID()));

		label = new Label(parent, SWT.NONE);
		label.setText("First name:");
		Text firstName = new Text(parent, SWT.BORDER);
		firstName.setText(emp.getFirstname());
		firstName.addModifyListener(new DataModifyListener(this));

		label = new Label(parent, SWT.NONE);
		label.setText("Initials:");
		Text initials = new Text(parent, SWT.BORDER);
		initials.setText(emp.getInitials());
		initials.addModifyListener(new DataModifyListener(this));

		label = new Label(parent, SWT.NONE);
		label.setText("Last name:");
		Text lastName = new Text(parent, SWT.BORDER);
		lastName.setText(emp.getLastname());
		lastName.addModifyListener(new DataModifyListener(this));

		label = new Label(parent, SWT.NONE);
		label.setText("Birthdate:");
		DateTime birthDate = new DateTime(parent, SWT.BORDER);
		try {
			if (emp.getBirthDate() != null)
				birthDate.setDate(emp.getBirthDate().get(Calendar.YEAR), emp
						.getBirthDate().get(Calendar.MONTH), emp.getBirthDate()
						.get(Calendar.DAY_OF_MONTH));

		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// birthDate.addSelectionListener(new DataModifyListener(this));
	}

	@Override
	public void setFocus() {
	}

}
